<template>
  <el-dialog :before-close="cancelPatient" :visible.sync="patientYYDetailVisible" append-to-body title="用药详情" @open="onOpen">
    <el-form ref="queryForm" :inline="true" :model="queryForm">
      <el-form-item label="就诊卡号" prop="visitCardNo">
        <el-input
          v-model="queryForm.visitCardNo"
          clearable
          placeholder="请输入就诊卡号"
          size="small"
        />
      </el-form-item>
      <!-- <el-form-item label="诊断结果" prop="diagnosisResult">
        <el-input
          v-model="queryForm.diagnosisResult"
          clearable
          placeholder="请输入诊断结果"
          size="small"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button icon="el-icon-search" size="mini" type="primary" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button
          v-hasPermi="['biobank:source:export']"
          :disabled="selectSamples.length == 0"
          icon="el-icon-download"
          size="mini"
          type="warning"
          @click="handleExport"
        >导出
        </el-button>
      </el-form-item>
    </el-form>
    <el-table ref="table" v-loading="loading" :data="data" border size="small"
              @selection-change="handleSelectionChange"
    >
      <el-table-column align="center" type="selection" width="55"/>
      <el-table-column align="center" label="id" prop="id"/>
      <el-table-column align="center" label="就诊卡号" prop="visitCardNo"/>
      <el-table-column align="center" label="药物名称" prop="drugsName"/>
      <el-table-column align="center" label="药量" prop="dosage"/>
      <el-table-column align="center" label="药物使用周期" prop="drugsUseCycle"/>
    </el-table>
    <pagination v-show="total>0" :limit.sync="queryForm.pageSize" :page.sync="queryForm.pageNum" :total="total"
                @pagination="searchQuery"
    />
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancelPatient">关 闭</el-button>
    </div>
  </el-dialog>
</template>1
<script>
import { getPatientYYInfoByIdCard,ExportPatientTreatmentInfoVoNew } from '@/api/biobank/sample'

export default {
  data() {
    return {
      queryForm: {
        pageNum: 1,
        pageSize: 10,
        visitCardNo: '',
        // diagnosisResult: '',
        orderByColumn: 'id',
        isAsc: 'DESC'
      },
      data: [],
      loading: false,
      selectSamples: [],
      total: 0
    }
  },
  props: {
    patientYYDetailVisible: Boolean,
    idCard:String
  },
  methods: {
    /**
     * @description: 查询接口数据
     * @return {*}
     */
    searchQuery() {
      this.loading = true
      // getPatientTreatmentInfo(this.queryForm).then(response => {
      //   this.data = response.rows
      //   this.total = response.total
      // }).finally(e => {
      //   this.loading = false
      // })
      this.queryForm.idCard = this.idCard
      getPatientYYInfoByIdCard(this.queryForm).then(res =>{
        if(res.rows){
          this.data = res.rows
          this.total= res.total
        }else{
          this.data = [];
          this.total = 0;
        }
      }).finally(e =>{
        this.loading = false
      })
    },

    /**
     * @description: 多选
     * @param selection
     * @return {*}
     */
    handleSelectionChange(selection) {
      this.selectSamples = selection
      this.selectSamples.forEach(item =>item.idCard = this.idCard)
      console.log(this.selectSamples)
    },

    /**
     * @description: 导出
     * @return {*}
     */
    handleExport() {
      let params = {
        list: [...this.selectSamples]
      }
      ExportPatientTreatmentInfoVoNew(params).then(response => {
        this.download(response.msg)
      })
    },

    /**
     * @description: 搜索
     * @return {*}
     */
    handleQuery() {
      this.queryForm.pageNum = 1
      this.searchQuery()
    },

    /**
     * @description: 重置
     * @return {*}
     */
    resetQuery() {
      this.queryForm = {
        pageNum: 1,
        pageSize: 10,
        visitCardNo: '',
        // diagnosisResult: '',
        orderByColumn: 'id',
        isAsc: 'DESC'
      }
      this.searchQuery()
    },

    /**
     * @description: 打开之前
     * @return {*}
     */
    onOpen() {
      this.resetQuery()
    },

    /**
     * @description: 取消
     * @return {*}
     */
    cancelPatient() {
      this.$emit('update:patientYYDetailVisible', false)
    }
  }
}
</script>
